package com.sharemedia.managers.db
{
	import com.sharemedia.interfaces.IDBCommand;
	import com.sharemedia.vos.Track;
	
	import flash.data.SQLConnection;
	import flash.data.SQLStatement;
	import flash.events.Event;
	import flash.events.SQLErrorEvent;
	import flash.events.SQLEvent;
	
	public class UpdateRatingCommand implements IDBCommand
	{
		private const RATE_TRACK:String = "UPDATE tracks SET likeNum = @likeNum, unlikeNum = @unlikeNum  WHERE uid=@uid";
		
		private var track:Track;
		public function UpdateRatingCommand( track:Track)
		{
			this.track = track;
		}
		
		public function execute(connection:SQLConnection):void
		{
			var addTracksStat:SQLStatement = new SQLStatement();
			addTracksStat.sqlConnection = connection;
			addTracksStat.text = RATE_TRACK;
			
			addTracksStat.addEventListener(SQLErrorEvent.ERROR, errorHandler);
			addTracksStat.addEventListener(SQLEvent.RESULT, insertResultHandler);
			
			addTracksStat.parameters["@uid"] = track.uid;	
			addTracksStat.parameters["@likeNum"] = track.likeNum;	
			addTracksStat.parameters["@unlikeNum"] = track.unlikeNum;	
			
			addTracksStat.execute();
		}
		
		/**
		 */
		private function errorHandler(e:SQLErrorEvent):void
		{
		}
		
		protected function insertResultHandler(event:Event):void
		{
		}
	}
}